package chatserver;
import java.util.Vector;


public class ChatRoom {
	private String roomName;
	private Vector<Chatter> clients=new Vector<Chatter>();
        //eo diu ay en
        private Boolean isPrivate;
        private String  password;
        //end
	public ChatRoom(String roomName, Boolean pri)
	{
		this.roomName=roomName;
                this.isPrivate = pri;
                password="***";
	}
        public String getRoomName()
        {
            return this.roomName;
        }
	public void addChatter(Chatter chatter)
	{
            if(chatter.getChatRoom()!=null)
                chatter.getChatRoom().removeChatter(chatter.getNick());
            clients.add(chatter);
            chatter.setChatRoom(this);
		//inform all about this new chatter
	}
	public void removeChatter(String nick)
	{
		for(int i=0;i<clients.size();i++)
		{
			if(clients.get(i).getNick().equals(nick))
			{
				clients.remove(i);
                                System.out.println("Chatter removed "+clients.size());
				break;
			}
		}
		//inform all about this new chatter
	}
        public Vector<Chatter> getChatters()
        {
            return clients;
        }
	public String toString()
	{
		//return room name and number of chatters
		return roomName+":"+clients.size()+","+isPrivate+","+password;
	}

        /**
         * @return the isPrivate
         */
        public Boolean getIsPrivate() {
            return isPrivate;
        }

        /**
         * @param isPrivate the isPrivate to set
         */
        public void setIsPrivate(Boolean isPrivate) {
            this.isPrivate = isPrivate;
        }

        /**
         * @return the password
         */
        public String getPassword() {
            return password;
        }

        /**
         * @param password the password to set
         */
        public void setPassword(String password) {
            this.password = password;
        }
}
